package leetcode;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * 描述:23. 合并K个升序链表
 *
 * @author Madison You
 * @created 0:37
 */
public class Hard_23_MergeKLists {

    public static void main(String[] args) {

    }

    public ListNode mergeKLists(ListNode[] lists) {
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = 0; i < lists.length; i++) {
            while (lists[i] != null) {
                integers.add(lists[i].val);
                lists[i] = lists[i].next;
            }
        }
        Collections.sort(integers);
        ListNode dynamic = new ListNode();
        ListNode other = dynamic;
        for (int i = 0; i < integers.size(); i++) {
            other.next = new ListNode(integers.get(i));
            other = other.next;
        }
        return dynamic.next;
    }

}
